package org.jgs1904.rabbitmq.workqueues;

import com.rabbitmq.client.Channel;
import org.jgs1904.utils.RabbitMqUtils;

import java.util.Scanner;

/**
 * @author: 默苍璃
 * @date: 2023-05-31 17:59
 * <p>
 * 发送线程
 */
public class Task01 {
    private static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {

        try (Channel channel = RabbitMqUtils.getChannel();) {
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            //从控制台当中接受信息
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入要发送的消息：");
            while (scanner.hasNext()) {
                String message = scanner.next();
                channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
                System.out.println("发送消息完成:" + message);

                System.out.println("输入要发送的消息：");
            }
        }
    }

}
